<template>
    <el-table :data="logArr" style="width: 100%">
        <el-table-column label="时间" width="180" prop="date">
        </el-table-column>
        <el-table-column label="大棚作物类型" width="180" prop="croptype">
        </el-table-column>
        <el-table-column label="生长状态" width="180">
            <template slot-scope="scope">
                <span>{{ sateObj[scope.row.growstate] }}</span>
            </template>
        </el-table-column>
        <el-table-column label="设备" width="180" prop="equipment">
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-switch
                    v-model="scope.row.value"
                    active-color="#13ce66"
                    @change="workChange(scope.row)"
                >
                </el-switch>
            </template>
            <!-- </el-tooltip> -->
        </el-table-column>
        <el-table-column label="工作完成情况" width="180">
            <template slot-scope="scope">
                <span
                    :style="{ color: scope.row.work == true ? 'green' : 'red' }"
                    >{{ workObj[scope.row.work] }}
                </span>
            </template>
        </el-table-column>
    </el-table>
</template>

<script>
import eventBus from "@/utils/eventBus.js"
export default {
    props: ["logArr"],
    data() {
        return {
            sateObj: {
                0: "幼苗期",
                1: "生长期",
                2: "成熟期",
            },
            workObj: {
                false: "未完成",
                true: "已完成",
            },
            // tableData: [
            //   {
            //     date: "2016-05-02",
            //     croptype: "草莓",
            //     growstate: 0,
            //     equipment: "浇灌系统",
            //     value: true,
            //     work: true,
            //   },
            //   {
            //     date: "2016-05-02",
            //     croptype: "草莓",
            //     growstate: 1,
            //     equipment: "浇灌系统",
            //     value: true,
            //     work: true,
            //   },
            //   {
            //     date: "2016-05-02",
            //     croptype: "草莓",
            //     growstate: 2,
            //     equipment: "浇灌系统",
            //     value: true,
            //     work: true,
            //   },
            // ],
        }
    },
    // created(){
    //   this.workChange()
    // },
    methods: {
        workChange(workInfo) {
            workInfo.work = workInfo.value
            // console.log(workInfo);
        },
        timeClickTop() {
            this.logArr.sort(function (a, b) {
                return Date.parse(a.date) - Date.parse(b.date)
            })
        },
        timeClickDon() {
            this.logArr.sort(function (a, b) {
                return Date.parse(b.date) - Date.parse(a.date)
            })
        },
    },
    mounted() {
        eventBus.$on("timeClickTop", this.timeClickTop)
        eventBus.$on("timeClickDon", this.timeClickDon)
    },
}
</script>

<style lang="less">
.el-table__header .cell {
    font-size: 14px;
    font-weight: 600;
    color: #7286a2;
}
</style>
